.TH std::regex_error 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::regex_error \- std::regex_error

.SH Synopsis
   Defined in header <regex>
   class regex_error;         \fI(since C++11)\fP

   Defines the type of exception object thrown to report errors in the regular
   expressions library.

   std-regex error-inheritance.svg

                                   Inheritance diagram

.SH Member functions

   constructor   constructs a regex_error object
                 \fI(public member function)\fP
   operator=     replaces the regex_error object
                 \fI(public member function)\fP
   code          gets the std::regex_constants::error_type for a regex_error
                 \fI(public member function)\fP

Inherited from std::runtime_error

Inherited from std::exception

.SH Member functions

   destructor   destroys the exception object
   \fB[virtual]\fP    \fI(virtual public member function of std::exception)\fP
   what         returns an explanatory string
   \fB[virtual]\fP    \fI(virtual public member function of std::exception)\fP

.SH Example


// Run this code

 #include <iostream>
 #include <regex>

 int main()
 {
     try
     {
         std::regex re("[a-b][a");
     }
     catch (const std::regex_error& e)
     {
         std::cout << "regex_error caught: " << e.what() << '\\n';
         if (e.code() == std::regex_constants::error_brack)
             std::cout << "The code was error_brack\\n";
     }
 }

.SH Possible output:

 regex_error caught: The expression contained mismatched [ and ].
 The code was error_brack
